document.querySelector('input[name="calculateBtn"]').addEventListener('click', function() {
    let totalAnimals = document.querySelector('input[name="totalAnimals"]').value;
    let totalLegs = document.querySelector('input[name="totalLegs"]').value;
    let chickens = 0;
    let rabbits = 0;

    rabbits = (totalLegs - 2 * totalAnimals) / 2;
    chickens = totalAnimals - rabbits;
    if(chickens < 0 || rabbits < 0 || !Number.isInteger(chickens) || !Number.isInteger(rabbits)){
        document.getElementById('result').textContent = '无解';
        document.getElementById('result').style.color = 'red';
    }else{
        document.getElementById('result').textContent = `分别有鸡${chickens}只，有兔子${rabbits}只`;
        document.getElementById('result').style.color = 'blue';
    }
});